/******************************************************************************
 * SVN­Versioning-Information:
 * ­­­­­­­­­­­­­­­­­­­­­­­­---------------------
 * $LastChangedRevision: 6 $
 * $LastChangedBy: c.a.duevel $
 * $LastChangedDate: 2009-08-26 15:12:37 +0000 (Wed, 26 Aug 2009) $
 * $HeadURL: http://robofight.googlecode.com/svn/trunk/Server/src/de/hft_stuttgart/botwar/server/model/Armament.java $
 ******************************************************************************/
package de.hft_stuttgart.botwar.server.model;

import de.hft_stuttgart.botwar.common.models.ArmamentInfo;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author pmv-mail@gmx.de,c.a.duevel@gmail.com
 */
@Entity
@Table(name = "tblArmament")
public class Armament implements Serializable {

    @Id
    private String name;
    @Column(nullable = false)
    private int power;
    @Column(nullable = false)
    private int range;
    @Column(nullable = false)
    private int weight;
    @Column(nullable = false)
    private int cost;
    @Column(nullable = false)
    private int levelRank;
    @OneToMany
    private Collection<RobotConfiguration> robots;

    /**
     * This constructor just exists because of the requirements of jpa.
     * Please do not use.
     * @deprecated
     */
    public Armament() {
    }
    /**
     * Creates a new armament
     * @param name The name of that armament.
     * @param power The damage that this armament makes per shot.
     * @param range The range this armament has.
     * @param weight Weight of this armament.
     * @param cost Cost of this armament in coins
     * @param levelRank The rank a player has to have to deserve this weapon
     */

    public Armament(final String name,
            final int power,
            final int range,
            final int weight,
            final int cost,
            final int levelRank) {
        setName(name);
        setFirePower(power);
        setRange(range);
        setWeight(weight);
        setCost(cost);
        setLevelRank(levelRank);
    }
/**
 *
 * @return name of this armament
 */
    public String getName() {
        return name;
    }
/**
 * Set the name of this weapon.
 * @param name The name it should have.
 */
    public void setName(final String name) {
        if (name == null) {
            throw new IllegalArgumentException("name may not be null");
        }
        this.name = name;
    }
/**
 *
 * @return cost The cost of that armament.
 */
    public int getCost() {
        return cost;
    }
/**
 *
 * @param cost The cost of that armament.
 */
    public void setCost(final int cost) {
        if (cost < 0) {
            throw new IllegalArgumentException("Cost must be positive!");
        }
        this.cost = cost;
    }
/**
 *
 * @param distance Range of this weapon.
 */
    public void setRange(final int distance) {
        if (distance < 0) {
            throw new IllegalArgumentException("Cost must be positive!");
        }
        this.range = distance;
    }
/**
 *
 * @return Range of this weapon.
 */
    public int getRange() {
        return range;
    }
/**
 *
 * @return Firepower aka damage of this weapon
 */
    public int getFirePower() {
        return power;
    }
/**
 *
 * @param firePower Firepower aka damage of this weapon
 */
    public void setFirePower(final int firePower) {
        if (firePower < 0) {
            throw new IllegalArgumentException("firePower must be positive!");
        }
        this.power = firePower;
    }
/**
 *
 * @return weight The weight of this weapon.
 */
    public int getWeight() {
        return weight;
    }
/**
 *
 * @param weight Weight of this weapon.
 */
    public void setWeight(final int weight) {
        if (weight < 0) {
            throw new IllegalArgumentException("weight must be positive!");
        }
        this.weight = weight;
    }
/**
 *
 * @return The rank a player has to have to get that weapon.
 */
    public int getLevelRank() {
        return levelRank;
    }
/**
 *
 * @param levelRank The rank a player has to have to get that weapon.
 */
    public void setLevelRank(final int levelRank) {
        if (levelRank < 1){
            throw new IllegalArgumentException(
                                    "Levelrank must be greater then zero!");
        }
        this.levelRank = levelRank;
    }
/**
 *
 * @return All the robotconfigurations using that robot
 */
    public Collection<RobotConfiguration> getRobots() {
        return robots;
    }
/**
 * @return ArmamentInfo object mirroring the information of that object.
 */
    public ArmamentInfo getInfo() {
        return new ArmamentInfo(levelRank, cost, range, power, weight, name);
    }
}
